package com.qiang.test01;

import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.Executors;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

public class MyThreadDemo03 {
    public static void main(String[] args) {
        ThreadPoolExecutor pool = new ThreadPoolExecutor(
                2,//核心线程数量
                5,//最大线程数量
                0, //空闲线程最长存活时间
                TimeUnit.SECONDS,//存活单位
                new ArrayBlockingQueue<>(5),//任务队列，也就是阻塞最大数量
                Executors.defaultThreadFactory(),//创建线程工厂
                new ThreadPoolExecutor.AbortPolicy());//任务的拒绝策略
        for (int i = 0; i < 15; i++) {
            //int j =i;
            int finalI = i;
            pool.submit(()->{
                System.out.println(Thread.currentThread().getName()+"==="+ finalI);
            });
        }

    }
}
